package function;

public class Log extends Function {
	private double base;
	private Function function;

	public Log(double b, Function f) {
		base = b;
		function = f;
	}

	public double getBase() {
		return base;
	}

	public void setBase(double base) {
		this.base = base;
	}

	public Function getFunction() {
		return function;
	}

	public void setFunction(Function function) {
		this.function = function;
	}

	public double evaluate(double x) {
		return Math.log(function.evaluate(x)) / Math.log(base);
	}

	public Function differentiate() {
		Function f = new Division(new Constant(1), new Power(new Multiply(
				function, new Constant(Math.log(base))), new Constant(1)));

		return new Multiply(function.differentiate(), f);
	}

	public String toString() {
		if (base == Math.E)
			return "Ln" + "(" + function.toString() + ")";
		return "Log" + base + "(" + function.toString() + ")";

	}

}
